package com.elasticsearch.wenzi.elastic.controller;

import com.elasticsearch.wenzi.elastic.response.ResultResponse;
import com.elasticsearch.wenzi.elastic.result.ProductEsResult;
import com.elasticsearch.wenzi.elastic.result.SearchResult;
import com.elasticsearch.wenzi.elastic.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/search")
public class SearchController {

	@Autowired
	private SearchService searchService;

	@PostMapping("/saveSearch")
	public ResultResponse saveSearch(@RequestBody List<ProductEsResult> list) throws IOException {
		return ResultResponse.success(searchService.saveSearch(list));
	}

	/**
	 * 查询数据
	 */
	@GetMapping("/searchKeywork")
	public ResultResponse searchKeywork(SearchResult searchResult){
		return ResultResponse.success(searchService.searchKey(searchResult));
	}
}